import { createSlice } from "@reduxjs/toolkit";
import type { RootState } from "./index";

interface CounterState {
  token: string ;
}

const initialState: CounterState = {
  token: localStorage.getItem("token") as string
};

export const userSlice = createSlice({
  name: "user",
  initialState,
  reducers: {
    addToken(state,payload){
      state.token = payload.payload
    }
  },
});

export const {addToken } = userSlice.actions;

export const selectToken = (state: RootState) => state.user.token;

export default userSlice.reducer;
